import { OAUTH_TOKEN, LOGOUT } from '@/store/modules/app/keys'
import * as api from '@/store/api/app'
import { proxyActions } from '@/store/vuex-helper'
import { ActionContext } from 'vuex'
import { AppState } from '@/store/modules/app/typings'

export default {
  [OAUTH_TOKEN] ({ commit }: ActionContext<AppState, any>, data: any) {
    return proxyActions(async () => {
      const response = await api.oauth_token(data)
      commit(OAUTH_TOKEN, response.data)
      return response.data
    }, OAUTH_TOKEN)
  },

  [LOGOUT] ({ commit }: ActionContext<AppState, any>) {
    commit(LOGOUT)
    return proxyActions(() => api.logout(), LOGOUT)
  }
}
